/*
 * Copyright 2012 Claude Houle claude.houle@gmail.com
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.google.code.mochaccino.framework.dbtool.impl;

import com.google.code.mochaccino.framework.dbtool.module.DBToolModule;
import com.google.code.mochaccino.framework.dbtool.sql.DriverManagedDataSource;
import com.google.code.mochaccino.framework.hibernate.provider.configuration.ConfigurationProviderDriverManaged;
import javax.sql.DataSource;
import org.apache.derby.jdbc.EmbeddedDriver;
import org.hibernate.cfg.Configuration;
import org.hibernate.dialect.DerbyDialect;

public class CommandLineTestModule extends DBToolModule {

	private ConfigurationProviderDriverManaged configurationProvider;

	@Override
	protected Configuration createConfiguration() {
		return getConfigurationProvider().get();
	}

	public ConfigurationProviderDriverManaged getConfigurationProvider() {
		if ( configurationProvider == null ) {
			configurationProvider = new ConfigurationProviderDriverManaged();
			configurationProvider.setDriverClass( EmbeddedDriver.class );
			configurationProvider.setUsername( "sa" );
			configurationProvider.setPassword( "" );
			configurationProvider.setUrl( "jdbc:derby:target/dbtool_tar;create=true" );
			configurationProvider.setDialect( DerbyDialect.class );
			configurationProvider.setClasses( new Class<?>[] { EntityA.class } );
		}
		return configurationProvider;
	}

	@Override
	protected DataSource createTargetDatasource() {
		DriverManagedDataSource ds = new DriverManagedDataSource( "jdbc:derby:target/dbtool_tar;create=true", "sa", "", EmbeddedDriver.class );
		return ds;
	}

	@Override
	protected DataSource createReferenceDatasource() {
		DriverManagedDataSource ds = new DriverManagedDataSource( "jdbc:derby:target/dbtool_ref;create=true", "sa", "", EmbeddedDriver.class );
		return ds;
	}
}
